package ext.tianma.util;

import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import org.apache.commons.lang.StringUtils;

import wt.doc.WTDocument;
import wt.part.WTPart;
import wt.util.WTException;
import ext.com.iba.IBAUtil;

/**
 * description 对象的iba属性工具类
 * @author xuge_ning
 * @date 2018-05-10
 */
public class IbaAttributeUtil {
	
	public static List<String> getAttributeValues(Object obj,String internalName){
		List<String> valueList = new ArrayList<String>();
		if(obj == null || StringUtils.isBlank(internalName)){
			return null;
		}
		Vector vector = null;
		try {
			if(obj instanceof WTPart){
				WTPart wtPart = (WTPart)obj;
				vector = IBAUtil.getIBAValue2(wtPart, internalName);
			} else if(obj instanceof WTDocument){
				WTDocument wtDocument = (WTDocument)obj;
				vector = IBAUtil.getIBAValue2(wtDocument, internalName);
			}
		} catch (RemoteException e) {
			e.printStackTrace();
		} catch (WTException e) {
			e.printStackTrace();
		}
		for(Object value:vector){
			String v = (String)value;
			valueList.add(v);
		}
		return valueList;
	}
	
	
	public static String getAttributeValue(Object obj,String internalName){
		String attributeValue = "";
		if(obj == null || StringUtils.isBlank(internalName)){
			return attributeValue;
		}
		Object value = null;
		try {
			if(obj instanceof WTPart){
				WTPart wtPart = (WTPart)obj;
				value = IBAUtil.getIBAValue(wtPart,internalName);
			} else if(obj instanceof WTDocument){
				WTDocument wtDocument = (WTDocument)obj;
				value = IBAUtil.getIBAValue(wtDocument, internalName);
			}
		} catch (RemoteException e) {
			e.printStackTrace();
		} catch (WTException e) {
			e.printStackTrace();
		}
		if(value != null){
			attributeValue = value.toString();
		}
		return attributeValue;
	}
	
	
	
	
	
	
}
